package com.srit.vgt.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.srit.vgt.common.utils.JSONUtils;
import com.srit.vgt.entity.EcrWeigh;
import com.srit.vgt.entity.Market;
import com.srit.vgt.entity.MarketTran;
import com.srit.vgt.main.DaoInject;
import com.srit.vgt.service.IEcrService;
import org.springframework.stereotype.Service;

import java.time.LocalDate;
import java.util.List;

/**
 * @author Yyming
 * @version 10.0
 * Created by Yyming on 2021/1/23
 */
@Service
public class EcrServiceImpl extends DaoInject implements IEcrService {

    @Override
    public Object getAllEcr(String marketId) {
        return ecrInfoDao.findAllByMarketId(marketId);
    }

    @Override
    public Object getAllEcrTran(String ecrId) {
//        Market market = marketDao.getById(id);
        LocalDate today = LocalDate.now();
        List<EcrWeigh> allByDateIsBetween = ecrWeighDao.findTran(today.plusDays(-8).toString(), today.plusDays(-1).toString(),ecrId);
//        JSONObject marketJson = JSONUtils.toJSONObject(market);
//        marketJson.put("trans", allByDateIsBetween);
        return allByDateIsBetween;
    }
}
